package io.demo5_字符流;

import java.io.*;

public class Test1 {
    public static void read(String[] args)throws Exception {
        Reader r=new FileReader("d:/1.txt");
        //读一字符
        //System.out.println((char)r.read());
//        int data;
//        while ((data=r.read())!=-1){
//            System.out.print((char)data);
//        }
        //读一数组
//        char[]ar=new char[4];
//        int len;
//        while ((len=r.read(ar))!=-1){
//            System.out.print(new String(ar,0,len));
//        }
        //缓冲流
//        BufferedReader br=new BufferedReader(r);
//        String msg;
//        while ((msg=br.readLine())!=null){
//            System.out.println(msg);
//        }
        InputStream is=new FileInputStream("d:/1.txt");
        //转换流
        InputStreamReader isr=new InputStreamReader(is,"gbk");
        BufferedReader br=new BufferedReader(isr);
        String msg;
        while ((msg=br.readLine())!=null){
            System.out.println(msg);
        }
        br.close();

    }

    public static void main(String[] args)throws Exception {
        Writer w=new FileWriter("d:/1.txt");
        w.write('a');
        w.write("hello");
        w.write("welcom".toCharArray(),0,2);
        w.flush();

        OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("d:/1.txt"),"gbk");
        BufferedWriter bw=new BufferedWriter(osw);
        bw.newLine();

    }
}
